/*
	QUBE
	Sandra Obermann - QPT 1 - 2012
	fhs33730 - 1110601021
	FH Salzburg - Studiengang MultiMediaTechnolgy
*/

// Include own written header files
#include "../include/Background.h"
#include "../include/DataManager.h"

// Cinder Basic Includes
#include "cinder/Rand.h"

// Used namespaces
using namespace ci;
using namespace ci::gl;

//Generate the random fixed and blinking stars
Background::Background(int numberOfStars)
{
	Rand random;
	for (int i = 0; i < numberOfStars; i++)
	{
		m_BlinkingStarPositions.push_back( Vec3f( random.posNegFloat( -500, 200 ), random.posNegFloat( -500, 200 ), random.posNegFloat( -500, 200 ) ) );
	}

	for (int i = 0; i < numberOfStars; i++)
	{
		m_FixedStarPositions.push_back( Vec3f( random.posNegFloat( -200, 200 ), random.posNegFloat( -200, 200 ), random.posNegFloat( -200, 200 ) ) );
	}
}

//Default Destructor
Background::~Background()
{
	
}

//Draw the random fixed and blinking stars
void Background::drawBackground()
{
	glBegin(GL_POINTS);

	// Star Color - white
	glColor3f( 1.0f, 1.0f, 1.0f );

	// Draw fixed Stars
	for ( unsigned int i = 0; i < m_FixedStarPositions.size(); i++ )
	{
		gl::vertex( m_FixedStarPositions[i] );
	}

	float alpha = sin( 2.0f * (float)DataManager::getInstance()->getTimer()->getSessionTime() );

	// Star Color - white and blinking with alpha value
	glColor4f( 1.0f, 1.0f, 1.0f, alpha );

	// Draw blinking Stars
	for ( unsigned int i = 0; i < m_BlinkingStarPositions.size(); i++ )
	{
		gl::vertex( m_BlinkingStarPositions[i] );
	}

	glEnd();
}